<?php
/**
 * @package tests
 */
require_once 'PHPUnit/Framework.php';
require_once dirname(__FILE__).'/../../../plugins/GraduaUtil/lib/test/Gradua_PHPUnit_Framework_TestCase.php';
class ServicesTest extends Gradua_PHPUnit_Framework_TestCase
{
    public function setup()
    {
      parent::setUp();
      ServiceValidator::$validateOutput = true;
      ServiceValidator::$validateInput  = true;
    }

    /**
     * @expectedException ServiceBrokenOutputContractException
     * {@source}
     */
    public function testShouldRaiseServiceBrokenOutputContractExceptionForWrongServiceOutput() {
      $schema = UnitTestsMockService::methodWithWrongMethodOutput();
    }

    /**
     * {@source}
     */
    public function testShouldNotValidateServiceOutputWhenConfigSaysSo() {
      ServiceValidator::$validateOutput = false;
      try {
        $schema = UnitTestsMockService::methodWithWrongMethodOutput();
      }
      catch (ServiceBrokenOutputContractException $e){
        $this->fail('Exception Should not raise with this configurations.');
      }
    }


    /**
     * @expectedException ServiceValidationException
     * {@source}
     */
    public function testShouldRaiseServiceValidationExceptionForWrongServiceInput() {
      $schema = UnitTestsMockService::methodThatExpectsInteger("aaa");
    }

    /**
     * {@source}
     */
    public function testShouldNotValidateServiceInputWhenConfigSaysSo() {
      ServiceValidator::$validateInput = false;
      try {
        $schema =  UnitTestsMockService::methodThatExpectsInteger("aaa");
      }
      catch (ServiceValidationException $e){
        $this->fail('Exception Should not raise with this configurations.');
      }
    }

}